abstract class FruitFactoryTemplate {
    // 模板方法（final防止子类覆盖）
    public final Fruit createFruit(String type) {
        validateType(type);
        Fruit fruit = createFruitInstance(type);
        postCreateHook(fruit);
        return fruit;
    }

    // 公共验证逻辑
    private void validateType(String type) {
        if (!type.matches("[A-Za-z]+")) {
            throw new IllegalArgumentException("Invalid fruit type format");
        }
    }

    // 抽象方法：由子类实现具体创建逻辑
    protected abstract Fruit createFruitInstance(String type);

    // 钩子方法：子类可选择性覆盖
    protected void postCreateHook(Fruit fruit) {
        System.out.println("默认后处理：水果已创建");
    }
}